set(DEMOLIB_SRCS
	register.cpp
	context.cpp
)

set(nosal_demolib_library_name nosal-${PROJECT_NAME})

add_library(${PROJECT_NAME} ${DEMOLIB_SRCS})

target_include_directories(${PROJECT_NAME}
	PUBLIC
		$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
		$<INSTALL_INTERFACE:include>
	PRIVATE
		$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
)

target_link_libraries(${PROJECT_NAME}
	PUBLIC
	#Threads::Threads
)

set_target_properties(${PROJECT_NAME} PROPERTIES
	OUTPUT_NAME ${nosal_demolib_library_name}
	POSITION_INDEPENDENT_CODE ON
)

add_library(nosal::demo-lib ALIAS ${PROJECT_NAME})

# -----------------------------

set(nosal_demolib_export_name "nosal-${PROJECT_NAME}")

include(FindPkgConfig)
if(PKG_CONFIG_FOUND)
	configure_file(${PROJECT_SOURCE_DIR}/files/pkgconfig/${nosal_demolib_export_name}.pc.in ${nosal_demolib_export_name}.pc @ONLY)
	install(
		FILES ${CMAKE_CURRENT_BINARY_DIR}/${nosal_demolib_export_name}.pc
		DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
	)
endif()

# Generate *-config.cmake file
include(CMakePackageConfigHelpers)

configure_package_config_file(
	${PROJECT_SOURCE_DIR}/files/cmake/${nosal_demolib_export_name}-config.cmake.in
	${CMAKE_CURRENT_BINARY_DIR}/${nosal_demolib_export_name}-config.cmake
	INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${nosal_demolib_export_name}
	NO_SET_AND_CHECK_MACRO # nosal::demolib does not set any path variables
)
# Generate *-config-version.cmake file
write_basic_package_version_file(
	${CMAKE_CURRENT_BINARY_DIR}/${nosal_demolib_export_name}-config-version.cmake
	COMPATIBILITY ExactVersion
)
# Install generated *-config.cmake and *-version.cmake files
install(
	FILES
		${CMAKE_CURRENT_BINARY_DIR}/${nosal_demolib_export_name}-config.cmake
		${CMAKE_CURRENT_BINARY_DIR}/${nosal_demolib_export_name}-config-version.cmake
	DESTINATION
		${CMAKE_INSTALL_LIBDIR}/cmake/${nosal_demolib_export_name}
)

# Install the actual target(s), i.e. the libraries and executables
install(
	TARGETS ${PROJECT_NAME}
	EXPORT ${nosal_demolib_export_name}-targets
	ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
	LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
	RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# Install exported targets, i.e. *-targets.cmake
install(
	EXPORT ${nosal_demolib_export_name}-targets
	DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${nosal_demolib_export_name}
	NAMESPACE nosal::
)
